package com.originalpoint.origin_server.result;

import lombok.Data;

;

/**
 *统一结果集封装
 */
@Data
public class Result<T> {
    //状态码，约定0成功，其他所有状态码均为失败
    private Integer ztm;

    //返回提示信息
    private String msg;

    //返回的数据类型
    private T data;

    public Integer getZtm() {
        return ztm;
    }

    public void setZtm(Integer ztm) {
        this.ztm = ztm;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    //带数据的成功返回
    public static Result BuildSuccess(Object data){
        Result r = new Result();
        r.setZtm(0);
        r.setMsg("操作成功！");
        r.setData(data);
        return r;
    }

    //不带数据的成功返回
    public static Result BuildSuccess(){
        return Result.BuildSuccess(null);
    }

    //失败返回
    public static Result BuildFail(Integer code, String msg){
        Result r = new Result();
        r.setZtm(code);
        r.setMsg(msg);
        return r;
    }
}
